//
//  BuyTableviewCell.m
//  HandWork
//
//  Created by 王阳阳 on 16/1/27.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "BuyTableviewCell.h"

@implementation BuyTableviewCell

- (void)dealloc
{
    [_titlelabel release];
    [_content release];
    [_img release];
    [super dealloc];
}
#pragma mark - 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creat];
    }
    return self;
}
- (void)creat
{
    /****标题店铺名称*****/
    self.titlelabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.titlelabel];
    [_titlelabel release];
    
    /****店铺*****/
    self.content = [[UILabel alloc]init];
    [self.contentView addSubview:self.content];
    [_content release];
    
    /****图片*****/
    
    self.img = [[UIImageView alloc]init];
    [self.contentView addSubview:self.img];
    [_content release];
    
    
}

#pragma mark - 布局
- (void)layoutSubviews
{
    [super layoutSubviews];
    /****标题****/
    self.titlelabel.frame = CGRectMake(5, 5, [UIScreen mainScreen].bounds.size.width - 10, 30);
    self.titlelabel.font = [UIFont systemFontOfSize:20];//字体大小
    self.titlelabel.textColor = [UIColor redColor];
    /****内容****/
    CGFloat h = [[self class] heightWihtText:_content.text];
    self.content.frame = CGRectMake(5, self.titlelabel.frame.size.height + self.titlelabel.frame.origin.y, [UIScreen mainScreen].bounds.size.width - 10, h);
    self.content.numberOfLines = 0;//不限制行数
    self.content.textColor = [UIColor grayColor];//字体颜色
    self.content.font = [UIFont systemFontOfSize:14];//字体大小
    
    /****图片****/
    CGFloat imgh = [[self class] heightWithPhoto:_j height:_i];
    self.img.frame = CGRectMake(5, h + 40, [UIScreen mainScreen].bounds.size.width - 10, imgh);
    
}
#pragma mark - 文字高度
+ (CGFloat)heightWihtText:(NSString *)text
{
    // 1.文本属性
    NSDictionary *dic = @{NSFontAttributeName: [UIFont systemFontOfSize:14]};
    // 2.预计尺寸
    CGSize s = CGSizeMake(375 - 20, 1000);
    // 3.计算
    CGRect r = [text boundingRectWithSize:s options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return r.size.height;
}
#pragma mark - 图片高度
+ (CGFloat)heightWithPhoto:(NSString *)weight height:(NSString *)height
{
    
    if (height != nil && weight != nil) {
        
        CGFloat h = (height.floatValue / weight.floatValue) * 355;
        return h;
    }
    else
    {
        return 0;
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
